﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Administrator
{
    public partial class ucDC : UserControl
    {
        private String DCCaption = "";
        private Int32 DCIndex = -1;
        public ucDC()
        {
            InitializeComponent();
        }

        //Заполнение полей настроек
        public void FillFields(Int32 DCIdx)
        {
            DCCaption = cMain.DC[DCIdx].Caption;
            DCIndex = DCIdx;
            tbCaption.Text = DCCaption;
        }
        //Применение настроек
        public Boolean ApplySetting()
        {
            if (DCCaption != "")
            {
                cMain.DC[DCIndex].Caption = DCCaption;
                cMain.DC[DCIndex].ItemAction.Changed = true;
                return true;
            }
            else 
            {
                MessageBox.Show(cConst.DC_CAPTION_ERROR_CAP, cConst.ERROR_CAPTION, MessageBoxButtons.OK, MessageBoxIcon.Stop);
                return false;
            }
        }

        private void tbCaption_TextChanged(object sender, EventArgs e)
        {
            // добавлена проверка симоволов на алфавит
            if (!(Checker.IsValidIdentifier((sender as TextBox).Text)))
            {
                MessageBox.Show(cConst.ERR_BAD_SYMBOL, cConst.ERROR_CAPTION, MessageBoxButtons.OK, MessageBoxIcon.Error);
                ((TextBox)sender).Text = DCCaption;
            }
            else
            {
                DCCaption = tbCaption.Text;
            }
        }
    }
}
